package org.brownflat.watergate.scm.svn;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.brownflat.watergate.scm.Revision;
import org.brownflat.watergate.scm.RevisionChange;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>&copy Rupert Jones 2011</p>
 *
 * @author rup
 */
public class SubversionRevision implements Revision, Serializable {
    private long revision;
    private String user;
    private String message;
    private Date date;
    private List<RevisionChange> revisionChanges;
    private String id;

    public SubversionRevision() {
    }

    public SubversionRevision(long number) {
        this.revision = number;
    }

    public SubversionRevision(String number) {
        revision = Long.parseLong(number);
    }

    public long getRevision() {
        return revision;
    }

    public void setRevision(long revision) {
        this.revision = revision;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public void setRevisionChanges(List<RevisionChange> revisionChanges) {
        this.revisionChanges = revisionChanges;
    }

    public List<RevisionChange> getRevisionChanges() {
        return revisionChanges;
    }

    public String toString() {
        return String.format("SubversionRevision-> [revision: %s][author: %s][date: %s][id: %s]", revision, user, date, id);
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37).append(getRevision()).append(getRevision()).toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) { return false; }
        if (obj == this) { return true; }
        if (obj.getClass() != getClass()) {
            return false;
        }
        SubversionRevision rhs = (SubversionRevision) obj;
        return new EqualsBuilder().append(getRevision(), rhs.getRevision()).append(getRevision(), rhs.getRevision()).isEquals();
    }
}
